import json
from pygal import maps

from country_codes import get_country_code

filename = 'population_data.json'
with open(filename) as file_obj:
    pop_data = json.load(file_obj)
    # print(pop_data)

cc_populations = []
for pop_dict in pop_data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        # print(country_name + str(population))
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population

wm = maps()
wm.add('2010', cc_populations)
wm.render_to_file('wm.svg')
